#include "sort.h"

void TestInsertSort()
{
	int nums[] = { 9, 6, 3, 8, 7, 1, 5, 2, 4,0 };
	int n = sizeof(nums) / sizeof(nums[0]);
	PrintNums(nums, n);

	InsertSort(nums, n);

	PrintNums(nums, n);
}
void TestShellSort()
{
	int nums[] = { 9, 6, 3, 8, 7, 1, 5, 2, 4,0 };
	int n = sizeof(nums) / sizeof(nums[0]);

	InsertSort(nums, n);

	PrintNums(nums, n);

	ShellSort(nums, n);

	PrintNums(nums, n);
}
void TestBubbleSort()
{
	int nums[] = { 9, 6, 3, 8, 7, 1, 5, 2, 4,0 };
	int n = sizeof(nums) / sizeof(nums[0]);
	PrintNums(nums, n);

	BubbleSort(nums, n);

	PrintNums(nums, n);

}

void TestSelectSort()
{
	int nums[] = { 9, 6, 3, 8, 7, 1, 5, 2, 4,0 };
	int n = sizeof(nums) / sizeof(nums[0]);
	PrintNums(nums, n);

	SelectSort(nums, n);

	PrintNums(nums, n);
}
void TestHeapSort()
{
	int nums[] = { 9, 6, 3, 8, 7, 1, 5, 2, 4,0 };
	int n = sizeof(nums) / sizeof(nums[0]);

	PrintNums(nums, n);

	HeapSort(nums, n);

	PrintNums(nums, n);
}

void TestQuickSort()
{
	int nums[] = { 6, 1, 2, 7, 9, 3, 4, 5, 10, 8 };
	int n = sizeof(nums) / sizeof(nums[0]);

	PrintNums(nums, n);

	QuickSort(nums, 0, n - 1);
	//QuickSortNonR(nums, 0, n - 1);
	PrintNums(nums, n);
}

void TestMergeSort()
{
	int nums[] = { 6, 1, 2, 7, 9, 3, 4, 5, 10, 8 };
	int n = sizeof(nums) / sizeof(nums[0]);

	PrintNums(nums, n);

	//QuickSort(nums, 0, n - 1);
	MergeSort(nums, n);
	PrintNums(nums, n);
}
void TestMergeSortNoR()
{
	int nums[] = { 6, 1, 2, 7, 3, 4, 5, 8 , 9, 10};
	int n = sizeof(nums) / sizeof(nums[0]);

	PrintNums(nums, n);

	//QuickSort(nums, 0, n - 1);
	MergeSortNoR(nums, n);
	PrintNums(nums, n);
}
void TestCountSort()
{
	int nums[] = { 6, 6, 1, 2, 7, 6, 3, 6, 4, 5, 6,  6, 9, 10 };
	int n = sizeof(nums) / sizeof(nums[0]);

	PrintNums(nums, n);

	//QuickSort(nums, 0, n - 1);
	CountSort(nums, n);
	PrintNums(nums, n);
}
void TestOP()
{
	int n = 10000000;
	int* nums1 = (int*)malloc(n * sizeof(int));
	int* nums2 = (int*)malloc(n * sizeof(int));
	int* nums3 = (int*)malloc(n * sizeof(int));
	int* nums4 = (int*)malloc(n * sizeof(int));
	int* nums5 = (int*)malloc(n * sizeof(int));
	int* nums6 = (int*)malloc(n * sizeof(int));
	int* nums7 = (int*)malloc(n * sizeof(int));


	for (int i = 0; i < n; ++i)
	{
		nums1[i] = i;
		nums2[i] = nums1[i];
		nums3[i] = nums1[i];
		nums4[i] = nums1[i];
		nums5[i] = nums1[i];
		nums6[i] = nums1[i];
		nums7[i] = nums1[i];
	}

	int begin1 = clock();
	//InsertSort(nums1, n);
	int end1 = clock();
	printf("InsertSort: %d\n", end1 - begin1);

	int begin2 = clock();
	ShellSort(nums2, n);
	int end2 = clock();
	printf("ShellSort: %d\n", end2 - begin2);

	int begin3 = clock();
	//BubbleSort(nums3, n);
	int end3 = clock();
	printf("BubbleSort: %d\n", end3 - begin3);

	int begin4 = clock();
	//SelectSort(nums4, n);
	int end4 = clock();
	printf("SelectSort: %d\n", end4 - begin4);

	int begin5 = clock();
	HeapSort(nums5, n);
	int end5 = clock();
	printf("HeapSort: %d\n", end5 - begin5);

	int begin6 = clock();
	QuickSort(nums6, 0, n - 1);
	int end6 = clock();
	printf("QuickSort: %d\n", end6 - begin6);

	int begin7 = clock();
	MergeSort(nums7, n);
	int end7 = clock();
	printf("MergeSort: %d\n", end7 - begin7);
}
int main()
{
	srand((unsigned int)time(0));
	//TestInsertSort();
	//TestShellSort();
	//TestBubbleSort();
	//TestSelectSort();
	//TestHeapSort();
	TestQuickSort();
	//TestCountSort();
	//TestMergeSort();
	//TestMergeSortNoR();

	//TestOP();
	return 0;
}